package leetcode;

import java.util.Arrays;

/**
 * description:
 * author:张腾
 * date:2021-06-28
 */

/**
 * 给定一组非负整数 nums，重新排列每个数的顺序（每个数不可拆分）使之组成一个最大的整数。
 */
public class leetcode179 {
    public String largestNumber(int[] nums) {
        int n = nums.length;
        String[] words = new String[n];
        for (int i = 0; i < n; i++) words[i] = String.valueOf(nums[i]);

        Arrays.sort(words,(a,b)->{
            //大的放前面
            return (b+a).compareTo(a+b);
        });
        if (words[0].equals("0")) return "0";
        StringBuffer sb = new StringBuffer();
        for (String word : words) {
            sb.append(word);
        }
        return sb.toString();
    }
}
